package com.lh0811.forge.dependency.security.core.model.entity;


import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

/**
 * 权限信息类
 *
 * @author lh0811
 * @date 2021/5/7
 */
@Getter
@Setter
public class SecurityAuthority implements Serializable {

    @Schema(description = "用户信息")
    private SecurityUser securityUser;

    @Schema(description = "过期时间")
    private Date overdueDate;

    @Schema(description = "用户id")
    private String userId;

    @Schema(description = "客户端类型")
    private String clientType;

    @Schema(description = "token口令")
    private String token;

    public SecurityAuthority() {
        super();
    }

    public SecurityAuthority(SecurityUser securityUser) {
        this.securityUser = securityUser;
        this.userId = securityUser.getId();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        SecurityAuthority that = (SecurityAuthority) o;
        return userId.equals(that.userId) && clientType.equals(that.clientType) && token.equals(that.token);
    }

    @Override
    public int hashCode() {
        return Objects.hash(userId, clientType, token);
    }

}
